1. Field Of The Invention
This invention relates to the field of single chip microprocessors and controllers. In particular, this invention relates to the utilization of input and output ports connected to the system bus of a microprocessor or controller for reading data from and writing data to external devices.
2. Prior Art
The use of input/output ports for providing communications between a microprocessor and external devices is well known. For example,: the Intel 8051 microcontroller provides for bidirectional ports, each consisting of a latch register, an output driver and an input buffer, each port being 8-bits wide.
During output operations, and assuming that one of the ports has been selected, data from the bus is placed into the latch register for the selected port. Once this occurs, the output driver of the selected port transfers the data stored in the latch register to the selected output device. Similarly, when reading data from an external device, the data from the device being read is placed on the pins of the selected port and loaded into the port input buffer, and then placed onto the internal system bus. In this input mode of operation, the data which is placed on the system bus is the data which is on the pins rather than the data stored in the latch register.
There is a third mode of operation, called read-modify-write mode. In this mode of operation, the data is read from the latch register, instead of the pins. The desired operation is performed and the results are written into the latch register for output on the pins. This entire operation is performed by a single instruction.
Generally, ports are written to or read from by the processor addressing particular locations in an on-chip RAM, which includes locations which are mapped onto the ports. In the prior art, in a fully configured system, with a 40 pin or 48 pin processor chip, there cannot be more than one or two ports available for communicating with external devices. (For example, utilizing a 40 pin processor chip with four ports, each 8-bit port requires 8 pin-outs for a total of 32 pins leaving only 8 pins for clock signals, control signals and power.) After 64K external program and data memories are coupled to the ports, generally only one port would be left to communicate with external devices. To overcome this problem, the prior art coupled a port expander to one of the ports. However, this technique has the disadvantage of causing a slow down in processor speed. That is, with a port expander, to read from or write to a device, at least two instructions must be executed, one to tell the port expander which real external port is being addressed, and a second instruction to actually move the data to or from the external port.
Another method of adding more input/output ports is to map them into the external memory by reserving a few external memory locations for the I/O ports. To the microcontroller and the program, these external ports look as if they are part of the external memory. The program may read from an input port as if it is a memory location. Similarly it can write to an output port as if it is a memory location. However, memory mapped I/O has the following disadvantages:
1. The hardware required to decode external memory addresses and control the external ports, is non trivial. The decoder consists of many logic gates. This logic occupies a lot of board space in a system, increases power consumption, and thus its overall cost. PA1 2. The ports are configured in the hardware as inputs and outputs and cannot be reconfigured under software control. PA1 3. A read-modify-write functionality cannot be externally reproduced because a memory mapped port cannot be made bidirectional. PA1 4. The external ports cannot be made bit addressable. PA1 5. External memory accesses are slower than internal register accesses. Since the ports are memory mapped, external memory instructions are used to access them. These instructions take longer to execute. Also more instructions are required to perform the same operations. Thus, the program increases in size and decreases in performance.
To overcome the foregoing problems, the subject invention is directed to a method and apparatus for coupling external ports to an onboard port so that the external ports can be addressed the same as onboard ports, in effect creating virtual ports.